package com.git.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.git.domain.DemoEntity;
import com.git.mapper.DemoMapper;
import com.git.mapper.DemoSqlMapper;
import com.git.service.DemoService;

@Service
public class DemoServiceImpl implements DemoService {
	@Autowired
	private DemoMapper demoMapper;
	private DemoSqlMapper demoSqlMapper;
	
	@Override
	@Cacheable(value="demo01",key="#id")
	public DemoEntity get(Integer id) {
		return this.demoMapper.selectByPrimaryKey(id);
	}
	@Override
	@Cacheable(value="demo01",key="#id")
	public DemoEntity get2(Integer id) {
		return this.demoMapper.selectByPrimaryKey(id);
	}
	
	
	@Override
	@CachePut(value = "demo01",key="#id")
	public DemoEntity update(Integer id) {
		DemoEntity demoEntity = new DemoEntity();
		demoEntity.setId(id);
		demoEntity.setStartDate(new Date());
		this.demoMapper.updateByPrimaryKey(demoEntity);
		return demoEntity;
	}
	
	@Override
	@CacheEvict(value = "demo01",key="#id")
	public void delete(Integer id) {
		this.demoMapper.deleteByPrimaryKey(id);
	}
}
